<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 85167
  Date: 2017/12/10
  Time: 11:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>字典类型管理</title>
    <c:import url="/WEB-INF/page/header.jsp"/>
</head>
<body>
<h4 class="m-t"></h4>
<div class="col-sm-12">
    <!-- Example Toolbar -->
    <div class="example-wrap">
        <div class="panel panel-default">
            <div class="panel-heading"><b>设备信息管理</b></div>
            <div class="panel-body">
                <form id="formSearch" class="form-inline">
                    <input type="hidden" id="bindStatus" value="${bindStatus}">
                    <div class="form-group">
                        <span>设备ID：</span>
                        <input type="text" class="form-control" id="id">
                        <span>设备别名：</span>
                        <input type="text" class="form-control" id="name">
                        <span>用户姓名：</span>
                        <input type="text" class="form-control" id="userName">
                        <span>电话：</span>
                        <input type="text" class="form-control" id="tel">
                        <br/><br/>
                        <span>代理商ID：</span>
                        <input type="text" class="form-control" id="distributorId">
                        <span>设备型号：</span>
                        <select id="devTypeId" class="form-control">
                            <option value="">全部</option>
                            <c:forEach items="${devTypes}" var="vo">
                                <option value="${vo.id}">${vo.name}</option>
                            </c:forEach>
                        </select>
                        <span>设备状态：</span>
                        <select id="devStatus" class="form-control">
                            <option value="">全部</option>
                            <option value="3">正常</option>
                            <option value="7">水满</option>
                            <option value="4">欠费</option>
                            <option value="1">待激活</option>
                            <option value="6">关机</option>
                            <option value="9">漏水</option>
                            <option value="8">缺水</option>
                            <option value="11">检修</option>
                            <option value="10">更换滤芯</option>
                        </select>
                        <%--<span>在线状态：</span>--%>
                        <%--<select id="onlineStatus" class="form-control">--%>
                            <%--<option value="">全部</option>--%>
                            <%--<option value="1">在线</option>--%>
                            <%--<option value="0">离线</option>--%>
                        <%--</select>--%>
                    </div>

                </form>
            </div>
        </div>
        <div class="example">
            <table id="dataTable2" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;" class="table table-hover table-condensed">
                <tr class="success"><td>滤芯不足10</td></tr>
                <tr class="warning"><td>流量或者时长不足10</td></tr>
            </table>
        </div>
        <div class="example">
            <div class="hidden-xs" id="dataTableToolbar" role="group">
                <div class="pull-left">
                    <c:if test="${bindStatus eq 1}">
                        <button type="button" class="btn btn-white btn-sm" onclick="exportData()">
                            <i class="glyphicon glyphicon-random">&nbsp;导出</i>
                        </button>
                    </c:if>
                    <button type="button" id="btn_query"
                            class="btn btn-white btn-rounded btn-outline btn-sm "
                            onclick="javascript: $('#dataTable').bootstrapTable('refresh');">
                        <i class="fa fa-search"></i>刷新
                    </button>
                </div>
                <div class="pull-right">
                    <button type="button" id="btn_query"
                            class="btn btn-white btn-rounded btn-outline btn-sm "
                            onclick="javascript: $('#dataTable').bootstrapTable('refresh');">
                        <i class="fa fa-search"></i>查询
                    </button>
                </div>
            </div>
            <table id="dataTable" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
            </table>
        </div>
    </div>
    <!-- End Example Toolbar -->
</div>
<c:import url="/WEB-INF/page/footer.jsp"/>
<script type="text/javascript">

    // Example Bootstrap Table Toolbar
    // -------------------------------
    (function () {

        $('#dataTable').bootstrapTable({
            url: base + "/admin/biz/devInfo/list",
            method: "post",
            classes: "table table-hover table-condensed",
            queryParams: function (params) {
                console.log(params.offset);
                var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    limit: params.limit,   //页面大小
                    offset: params.offset,  //页码
                    id: $("#id").val(),
                    userName: $("#userName").val(),
                    name: $("#name").val(),
                    userId: $("#userId").val(),
                    tel: $("#tel").val(),
                    bindStatus: $("#bindStatus").val(),
                    devTypeId: $("#devTypeId").val(),
                    devStatus: $("#devStatus").val(),
                    distributorId: $("#distributorId").val(),
                    // onlineStatus:$("#onlineStatus").val()
                };
                return temp;
            },
            toolbar: '#dataTableToolbar',
            pagination: true,
            sidePagination: "server",
            rowStyle: rowStyle,
            columns: [{
                checkbox: true
            }, {
                field: 'id',
                title: '设备ID'
            }, {
                field: 'name',
                title: '设备别名'
            }, {
                field: 'userName',
                title: '用户姓名'
            }, {
                field: 'tel',
                title: '用户手机'
            }, {
                field: 'distributorId',
                title: '代理商ID'
            }, {
                field: 'distributorName',
                title: '代理商名称'
            }, {
                field: 'billTypeId',
                title: '模式',
                formatter: function (value, row, index) {
                    if (value == 0) {
                        return "流量";
                    } else if (value == 1) {
                        return "时长";
                    } else {
                        return "买断";
                    }
                }
            }, {
                field: 'devStatus',
                title: '设备状态',
                formatter: function (value, row, index) {
                    if (value == 0) {
                        return "备用";
                    } else if (value == 1) {
                        return "待激活";
                    } else if (value == 2) {
                        return "出厂测试状态";
                    } else if (value == 3) {
                        return "正常制水";
                    } else if (value == 4) {
                        return "欠费";
                    } else if (value == 5) {
                        return "故障";
                    } else if (value == 6) {
                        return "关机";
                    } else if (value == 7) {
                        return "水满";
                    } else if (value == 8) {
                        return "缺水";
                    } else if (value == 9) {
                        return "漏水";
                    } else if (value == 10) {
                        return "滤芯待复位";
                    } else if (value == 11) {
                        return "硬件测试";
                    }
                }
            }, {
                field: 'imei',
                title: 'imei'
            }, {
                field: 'onlineStatus',
                title: '在线状态',
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return "在线";
                    } else {
                        return "离线"
                    }
                }
            }, {
                field: 'repairNum',
                title: '报修次数'
            }, {
                field: 'asignal',
                title: '信号强度'
            }, {
                formatter: function (value, row, index) {
                    return [
                        '<a class="btn btn-success  btn-xs" href="javascript:view(' + row.id + ')">' +
                        '<i class="fa fa-search-plus"></i>查看' +
                        '</a>&nbsp;',
                        '<a class="btn btn-success  btn-xs" href="javascript:recharge(' + row.id + ',' + row.billTypeId + ')">' +
                        '<i class="glyphicon glyphicon-pencil"></i>充值' +
                        '</a>&nbsp;',
                        '<a class="btn btn-success  btn-xs" href="javascript:unRecharge(' + row.id + ',' + row.billTypeId + ')">' +
                        '<i class="glyphicon glyphicon-pencil"></i>负充值' +
                        '</a>&nbsp;',
                        '<a class="btn btn-success  btn-xs" href="javascript:start(' + row.id + ')">' +
                        '<i class="glyphicon glyphicon-pencil"></i>开机' +
                        '</a>&nbsp;</br>',
                        '<a class="btn btn-success  btn-xs" href="javascript:stop(' + row.id + ')">' +
                        '<i class="glyphicon glyphicon-pencil"></i>关机' +
                        '</a>&nbsp;',
                        '<a class="btn btn-success  btn-xs" href="javascript:force(' + row.id + ')">' +
                        '<i class="glyphicon glyphicon-pencil"></i>强冲' +
                        '</a>&nbsp;',
                        '<a class="btn btn-danger btn-xs" href="javascript:unBind(' + row.id + ')">' +
                        '<i class="fa fa-trash"></i>解绑' +
                        '</a>&nbsp;',
                        '<a class="btn btn-danger btn-xs" href="javascript:devInit(' + row.id + ')">' +
                        '<i class="fa fa-trash"></i>恢复出厂设置' +
                        '</a>&nbsp;'
                    ].join('');
                },
                title: '操作'
            }]
        });
    })();

    function rowStyle(row, index) {
        if (row.filterFlag == 1) {
            return {classes: "success"}
        }
        var style = "";
        if (row.billTypeId == 0) {
            if (row.remainFlow < 10) {
                style = 'warning';
            }
        } else if (row.billTypeId == 1) {
            if (row.remainTime < 10) {
                style = 'warning';
            }
        }

        return {classes: style}
    }

    function exportData() {
        window.open(base + "/admin/biz/devInfo/export");
    }

    function devInit(id) {
        swal({
            title: "确认要将设备恢复出厂设置吗？(恢复出厂设置后所有数据丢失，请注意，需要执行30秒！)",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
            doChgStatus(base + "/admin/biz/devInfo/devInit?id=" + id);
        });
    }

    function view(id) {
        openDialogView("查看设备信息", base + "/admin/biz/devInfo/view?id=" + id);
    }

    function filterInit(id, level) {
        swal({
            title: "确认要初始化的第" + level + "级滤芯吗？",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
            doChgStatus(base + "/admin/biz/devInfo/filterInit?id=" + id + "&level=" + level);
        });
    }

    function start(id) {
        swal({
            title: "您确定要开机吗",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
            doChgStatus(base + "/admin/biz/devInfo/start?id=" + id);
        });
    }

    function stop(id) {
        swal({
            title: "您确定要关机吗",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
            doChgStatus(base + "/admin/biz/devInfo/stop?id=" + id);
        });
    }

    function force(id) {
        swal({
            title: "您确定要强冲吗",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
            doChgStatus(base + "/admin/biz/devInfo/force?id=" + id);
        });
    }

    function unBind(id) {
        swal({
            title: "您确定要解绑吗",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
            doChgStatus(base + "/admin/biz/devInfo/unBind?id=" + id);
        });
    }

    function view(id) {
        openDialogView("查看设备信息", base + "/admin/biz/devInfo/view?id=" + id);
    }

    function recharge(id, bilTypeId) {
        var title = "";
        if (bilTypeId == 0) {
            title = "请输入流量(L)"
        } else if (bilTypeId == 1) {
            title = "请输入时长(天)";
        } else {
            swal("买断模式不允许充值");
            return;
        }
        var index = top.layer.prompt({
            title: title,
            formType: 0 //prompt风格，支持0-2
        }, function (pass) {
            top.layer.close(index);
            $.ajax({
                url: base + "/admin/biz/devInfo/recharge/" + id + "/" + pass,
                dataType: "json",
                success: function (data) {
                    if (data.code == 0) {
                        swal("保存成功！", "", "success");
                        setTimeout(function () {
                            top.layer.close(index);
                        }, 1000);

                    } else {
                        console.log(data);
                        if (data.msg) {
                            swal("保存失败！", data.msg, "error");
                        } else {
                            swal("保存失败！", data.resultMsg, "error");
                        }

                    }
                }
            })

        });
    }

    function unRecharge(id) {
        layer.config({
            extend: 'extend/layer.ext.js'
        });
        var index = top.layer.prompt({
            title: '输入充值数量',
            formType: 0 //prompt风格，支持0-2
        }, function (pass) {
            $.ajax({
                url: base + "/admin/biz/devInfo/unRecharge/" + id + "/" + pass,
                dataType: "json",
                success: function (data) {
                    if (data.code == 0) {
                        swal("保存成功！", "", "success");
                        setTimeout(function () {
                            top.layer.close(index);
                        }, 1000);

                    } else {
                        console.log(data);
                        if (data.msg) {
                            swal("保存失败！", data.msg, "error");
                        } else {
                            swal("保存失败！", data.resultMsg, "error");
                        }

                    }
                }
            })
            top.layer.close(index);
        });
    }

    function devInit(id) {
        swal({
            title: "您确定要恢复出厂吗",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
            doChgStatus(base + "/admin/biz/devInfo/devInit?id=" + id);
        });
    }
</script>
</body>
</html>
